<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 1.公共的属性,写到构造函数里面
        function Star(name, age) {
            this.name = name
            this.age = age
            // this.sayHi = function () {
            //     console.log('hi')
            // }
        }
        // 2.公共的方法写到原型对象上,节约了内存
        Star.prototype.sayHi = function(){
            console.log('hi')
        }
        const zjl = new Star('周杰伦', 18)
        const ldh = new Star('刘德华', 29)

        console.log(zjl, ldh)
        console.log(zjl,sayHi === ldh.sayHi) // true

        // ==> 总结
        // 1.公共属性定义在构造函数里面
        // 2.公共方法我们放在原型对象上
    </script>
</body>
</html>